<!-- 正文开始 -->
<div class="open-form">
    <div class="open-model">
        <div class="open-auto">
            <!-- 头部操作栏 -->
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <button id="processInfoBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加
                        </button>
                        <button id="processInfoBtnExport" class="layui-btn icon-btn"><i
                                class="layui-icon">&#xe67d;</i>导出
                        </button>

                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="processInfoTable" lay-filter="processInfoTable"></table>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </div>
</div>

<script id="processInfoAddWindow" type="text/html">
    <div class="open-form">
        <div class="open-model">
            <div class="open-auto" style="padding-top: 5px;">
                <!-- 表格 -->
                <table class="layui-table" id="processInfoAddTable" lay-filter="processInfoAddTable"></table>
            </div>
            <div class="layui-form-item text-right">
                <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
                <button class="layui-btn" lay-filter="processInfoAddSubmit" lay-submit>保存</button>
            </div>
        </div>
    </div>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'laydate', 'admin', 'laytpl', 'tableTreeDj', 'config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var laydate = layui.laydate;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laytpl = layui.laytpl;
        var tableTree = layui.tableTreeDj;

        // 回显工序数据
        var data = admin.getTempData('data');

        // 渲染表格
        var insTb = table.render({
            elem: '#processInfoTable',
            url: config.base + 'enterprise/product/admin/processInfo/list?productTypeId=' + data.id,
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'checkbox'}
                , {type: 'numbers', title: '序号'}
                , {field: 'nodeNames', align: 'center', title: '工段节点名称'}
                , {field: 'nodeNames', align: 'center', title: '适用责任生产车间'}
                , {field: 'nodeCodes', align: 'center', title: '工段节点编号'}
                , {field: 'remark', align: 'center', title: '备注说明'}

                , {
                    field: 'nodeTypes', align: 'center', title: '节点类别', templet: function (d) {
                        if (d.nodeTypes == '1') {
                            return '流水线节点（线排配）';
                        } else if (d.nodeTypes == '2') {
                            return '机加工节点（站排配）';
                        } else if (d.nodeTypes == '3') {
                            return '单一离散节点（站排配）';
                        }
                    }
                }
                , {
                    field: 'isDetectionAll', align: 'center', title: '抽检', templet: function (d) {
                        if (d.isDetectionAll == '0') {
                            return '是';
                        } else if (d.isDetectionAll == '1') {
                            return '否';
                        }
                    }
                }
                , {
                    field: 'isOutsource', align: 'center', title: '是否支持委外', templet: function (d) {
                        if (d.isOutsource == '0') {
                            return '不支持';
                        } else if (d.isOutsource == '1') {
                            return '支持';
                        }
                    }
                }
                , {field: 'createTime', align: 'center', title: '创建时间'}
            ]],
            done: function (res, curr, count) {
            }
        });

        $('#processInfoBtnAdd').click(function () {
            showProcessInfoAddEditModel(data);
        });

        function showProcessInfoAddEditModel(data) {
            var addProcessIndex = admin.open({
                type: 1,
                area: ['1400px', '85%'],
                title: '添加工序',
                content: $('#processInfoAddWindow').html(),
                success: function () {
                    var insTb = table.render({
                        elem: '#processInfoAddTable',
                        url: config.base + 'enterprise/product/admin/processInfo/list?productTypeId=' + data.id + '&type=1',
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            , {type: 'numbers', title: '序号'}
                            , {field: 'nodeNames', align: 'center', title: '工段节点名称'}
                            , {field: 'nodeNames', align: 'center', title: '适用责任生产车间'}
                            , {field: 'nodeCodes', align: 'center', title: '工段节点编号'}
                            , {field: 'remark', align: 'center', title: '备注'}

                            , {
                                field: 'nodeTypes',
                                align: 'center',
                                title: '节点类别',
                                templet: function (d) {
                                    if (d.nodeTypes == '1') {
                                        return '流水线节点（线排配）';
                                    } else if (d.nodeTypes == '2') {
                                        return '机加工节点（站排配）';
                                    } else if (d.nodeTypes == '3') {
                                        return '单一离散节点（站排配）';
                                    }
                                }
                            }
                            , {
                                field: 'isDetectionAll',
                                align: 'center',
                                title: '抽检',
                                templet: function (d) {
                                    if (d.isDetectionAll == '0') {
                                        return '是';
                                    } else if (d.isDetectionAll == '1') {
                                        return '否';
                                    }
                                }
                            }
                            , {
                                field: 'isOutsource',
                                align: 'center',
                                title: '是否支持委外',
                                templet: function (d) {
                                    if (d.isOutsource == '0') {
                                        return '不支持';
                                    } else if (d.isOutsource == '1') {
                                        return '支持';
                                    }
                                }
                            }
                            , {field: 'createTime', align: 'center', title: '创建时间'}
                        ]],
                        done: function (res, curr, count) {
                            // 设置背景颜色
                            let backgroundColor = "#eaeaea";
                            let table_data = res.data;
                            for (let i = 0; i < table_data.length; i++) {
                                let elect = table_data[i].elect;
                                if (!elect) {
                                    console.log(table_data[i])
                                    $('th[data-field="0"] input[type="checkbox"]').prop('disabled', true); // 禁止全选
                                    $(".layui-table tr[data-index=" + i + "] input[type='checkbox']").prop('disabled', true); //禁止部分选择
                                    $(".layui-table tr[data-index=" + i + "] input[type='checkbox']").next().addClass('layui-btn-disabled');
                                    $('div[lay-id="processInfoAddTable"]').find('tr[data-index =' + i + ']').css("background-color", backgroundColor);
                                }
                            }
                        }
                    });

                    form.on('submit(processInfoAddSubmit)', function (d) {
                        var para = {};
                        var check = table.checkStatus('processInfoAddTable');
                        var ids = [];
                        $(check.data).each(function (i, o) {// o 即为表格中一行的数据
                            ids.push(o.id);
                        });
                        para["processIds"] = ids;
                        para["productTypeId"] = data.id;
                        admin.req('enterprise/product/admin/productTypeProcess/add', para, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('processInfoTable');
                                layer.close(addProcessIndex);
                            } else {
                                layer.closeAll('page');
                            }
                        }, 'POST');
                    })
                }
            })
        }

    });
</script>